package io.renren.modules.teacher.controller;

import cn.hutool.core.lang.Snowflake;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.sys.controller.AbstractController;
import io.renren.modules.teacher.service.TeacherCourseManageService;
import io.renren.modules.teacher.service.TeacherPersonInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/teacher/courseManage")
public class TeacherCourseManageController extends AbstractController {
    @Autowired
    private TeacherCourseManageService teacherCourseManageService;
    /*
    获得课程管理课程
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String,Object> params){
        params.put("userId",getUserId()+"");

        PageUtils pageUtils = teacherCourseManageService.queryList(params);
        return R.ok().put("page",pageUtils);
    }
    /*
    获得表单数据
     */
    @GetMapping("/data/{courseId}")
    public R data(@PathVariable("courseId") String courseId){
        Map<String, Object> result = teacherCourseManageService.queryData(courseId);
        return R.ok().put("data",result);
    }
    /*
    新增课程
     */
    @PostMapping("/save")
    public R save(@RequestBody Map<String, Object> dataForm){
        dataForm.put("userId",getUserId()+"");
        teacherCourseManageService.save(dataForm);
        return R.ok();
    }
    /*
    修改课程
     */
    @PostMapping("/update")
    public R update(@RequestBody Map<String, Object> dataForm){
        teacherCourseManageService.update(dataForm);
        return R.ok();
    }
    /*
    删除
     */
    @PostMapping("/delete")
    public R delete(@RequestBody String[] listIds){
        System.out.println(listIds);
        teacherCourseManageService.delete(listIds);
        return R.ok();
    }
    /*
    新增课程章节
     */
    @PostMapping("/addChapter")
    public R addChapter(@RequestBody Map<String, Object> form){
        teacherCourseManageService.addChapter(form);
        return R.ok();
    }

    /*
    获得课程每一个章节的数据
     */
    @GetMapping("/getChapter/{chapterId}")
    public R getChapter(@PathVariable String chapterId){
        Map<String, Object> result = teacherCourseManageService.getChapter(chapterId);
        return R.ok().put("data",result);
    }
    /*
    更新章节内容
     */
    @PostMapping("/updateChapter")
    public R updateChapter(@RequestBody Map<String, Object> formData){
        teacherCourseManageService.updateChapter(formData);
        return  R.ok();
    }

    //清除章节内容
    @PostMapping("/delContent")
    public R delContent(@RequestBody Map<String, Object> formData){
        teacherCourseManageService.delChapterContent(formData);
        return  R.ok();
    }
}
